import Request from './request'
import {
	API_BASE_URL,
	loginls,
	cms_service,
	shopnews,
	API_URL
} from '../config.js'
const https = new Request();
const http = new Request();
const loginl = new Request();
const cms = new Request();
const shopnew = new Request();
http.setConfig((config) => {
	config.baseUrl = API_BASE_URL;
	return config
})

http.interceptor.request((config, cancel) => {
	let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'
	config.header = {
		...config.header,
		'Authorization': uni.getStorageSync(loginKey),
		userSource: 1, //用户类型 1:C端用户  2:员工
	}
	/*
	if (!token) {
	  cancel('token 不存在')
	}
	*/
	return config;
})

http.interceptor.response((response) => {
	return response;
})
// end

https.setConfig((config) => {
	config.baseUrl = API_URL;
	return config
})

https.interceptor.request((config, cancel) => {
	let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'
	config.header = {
		...config.header,
		'Authorization': uni.getStorageSync(loginKey),
		userSource: 1, //用户类型 1:C端用户  2:员工
	}
	/*
	if (!token) {
	  cancel('token 不存在')
	}
	*/
	return config;
})

https.interceptor.response((response) => {
	return response;
})
// end

loginl.setConfig((config) => {
	config.baseUrl = loginls;
	return config
})

loginl.interceptor.request((config, cancel) => {
	let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'
	config.header = {
		...config.header,
		'Authorization': uni.getStorageSync(loginKey),
		userSource: 1, //用户类型 1:C端用户  2:员工
	}
	/*
	if (!token) {
	  cancel('token 不存在')
	}
	*/
	return config;
})

loginl.interceptor.response((response) => {
	return response;
})





cms.setConfig((config) => {
	config.baseUrl = cms_service;
	return config
})

cms.interceptor.request((config, cancel) => {
	let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'
	config.header = {
		...config.header,
		'Authorization': uni.getStorageSync(loginKey),
		userSource: 1, //用户类型 1:C端用户  2:员工
	}
	/*
	if (!token) {
	  cancel('token 不存在')
	}
	*/
	return config;
})

cms.interceptor.response((response) => {
	return response;
})






shopnew.setConfig((config) => {
	config.baseUrl = shopnews;
	return config
})

shopnew.interceptor.request((config, cancel) => {
	let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'
	config.header = {
		...config.header,
		'Authorization': uni.getStorageSync(loginKey),
		userSource: 1, //用户类型 1:C端用户  2:员工
	}
	/*
	if (!token) {
	  cancel('token 不存在')
	}
	*/
	return config;
})

shopnew.interceptor.response((response) => {
	return response;
})
export {
	http,
	loginl,
	cms,
	shopnew,
	https
};
